"""
---------------------------------------------------------------------
- File: logs.py
- Date: 2025/11/19
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 日志接口
---------------------------------------------------------------------
"""

from fastapi import APIRouter, Depends, Query

# from app.core.dependency import get_current_user
from app.core.dependency import get_service_dependency
from app.core.response import ResponseBase, ResponseSuccess
from app.schemas.system.logs import LogsReadListWithUserAndUserName
from app.service.service_logs import ServiceLogs

logs_router = APIRouter(prefix="/system/logs", tags=["系统管理-日志管理"])

ServiceLogs = get_service_dependency(ServiceLogs)


@logs_router.get("/", summary="获取日志列表", response_model=ResponseBase[LogsReadListWithUserAndUserName])
async def get_logs(
    page: int = Query(1, ge=1, description="页码"),
    size: int = Query(3, le=100, description="每页数量"),
    filter_value: str = Query("", description="搜索关键字", alias="filter"),
    service_logs: ServiceLogs = Depends(),
):
    """
    成功认证用户的请求日志列表
    """
    total, logs = await service_logs.get_multi(skip=(page - 1) * size, limit=size, filter_value=filter_value)
    if logs is None:
        logs = []
    data = LogsReadListWithUserAndUserName(list=logs, total=total)
    return ResponseSuccess(data=data)
